import pygame
from pygame.locals import *
import sys

class Options():
        options_yoffset= 340
	def __init__(self,screen,bg,font1,font2,ball,title,options,results,default_option=0):

                self.current=default_option
                self.ball=ball
                
                self.options=options
                self.results= results
                self.screen=screen
                self.bg=bg
                title_game_label = font2.render("DiDiBall", 1, (255,255,0))

                title_label = font1.render(title, 1, (35,35,255))
                screen.blit( bg, (0,0))
                width= screen.get_rect().width
                self.title_game_left=width*0.5-title_game_label.get_width()*0.5
                screen.blit(title_game_label,(self.title_game_left,200))
                self.title_left=width*0.5-title_label.get_width()*0.5
                screen.blit(title_label,(self.title_left,300))
                i=0
                #keys
                for opt in self.options:
                        label = font1.render(opt, 1, (0,0,0))
                        screen.blit(label,(self.title_game_left,self.options_yoffset+i*40))
                        i+=1
                self.blit_ball()
                pygame.display.update()

        def unblit_ball(self):
            self.screen.blit(self.bg,(self.title_game_left-50,self.options_yoffset+self.current*40),self.ball.get_rect())

        def blit_ball(self):
            self.screen.blit(self.ball.get_surface(),(self.title_game_left-50,self.options_yoffset+self.current*40))

        def up(self):
            if self.current > 0:
                self.unblit_ball()
                self.current-=1
                self.blit_ball()
        def down(self):
            if self.current < len(self.options)-1:
                self.unblit_ball()
                self.current+=1
                self.blit_ball()

	def loop(self):
	    while 1:
    
                for event in pygame.event.get():
                    if event.type == QUIT:
                            sys.exit()
                      
                    keys = pygame.key.get_pressed()
                    
                    players = ()
                    
                    if keys[ K_UP]:
                                self.up()
                    elif keys[ K_DOWN]: 
                                self.down()
                    elif keys[ K_RETURN]:
                        return self.results[self.current]
                    elif keys[ K_RIGHT]: players = (True,True)
                    elif keys[ K_ESCAPE]: 
                                sys.exit()
		pygame.display.update()
